package com.ht.medicaltreatment.fragment.haocai2

import android.graphics.Color
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.ht.medicaltreatment.R
import com.ht.medicaltreatment.bean.ApplyRecordPage

class ConsumableRecordAdapter :
    BaseQuickAdapter<ApplyRecordPage, BaseViewHolder>(R.layout.item_consumable_record_layout) {
    private var authSign = 0

    init {
        addChildClickViewIds(R.id.btnNegaive,R.id.btnPositive,R.id.btnPrepare,R.id.btnSend)
    }

    override fun convert(holder: BaseViewHolder, item: ApplyRecordPage) {
        val recyclerView = holder.getView<RecyclerView>(R.id.recyclerView)
        recyclerView.layoutManager =
            LinearLayoutManager(context).apply { orientation = LinearLayoutManager.HORIZONTAL }
        val adapter = ConsumableRecordChildAdapter()
        recyclerView.adapter = adapter
        adapter.setNewInstance(item.projectConsumableRecordDetailsList)

        holder.setText(R.id.titleTime, "订单提交时间：" + item.createTime)
        holder.setText(R.id.tvName, "申请人："+item.username)

        holder.setGone(R.id.btnNegaive, true)
        holder.setGone(R.id.btnPositive, true)
        holder.setGone(R.id.btnPrepare, true)
        holder.setGone(R.id.btnSend, true)

        //(0:待审批;1:同意;2:拒绝;3:寄出;4:签收)   同意后，显示【准备耗材】按钮
        when (item.status) {
            0 -> {
                if(authSign == 1){
                    holder.setVisible(R.id.btnNegaive, true)
                    holder.setVisible(R.id.btnPositive, true)
                }
                holder.setText(R.id.tvTime, "待审批")
                holder.setTextColor(R.id.tvTime, context.getColor(R.color.colorTextGray))
            }

            1 -> {
                holder.setVisible(R.id.btnPrepare, true)
                holder.setVisible(R.id.btnSend, true)
                holder.setText(R.id.tvTime, "同意")
                holder.setTextColor(R.id.tvTime, context.getColor(R.color.green))
            }

            2 -> {
                holder.setText(R.id.tvTime, "拒绝")
                holder.setTextColor(R.id.tvTime, Color.RED)
                holder.setVisible(R.id.tvRefuse,true)
                holder.setText(R.id.tvRefuse,"拒绝理由："+item.remark)
            }

            3 -> {
                holder.setText(R.id.tvTime, "待签收")
            }

            4 -> {
                holder.setText(R.id.tvTime, "已签收")
            }
        }
    }

    fun setAuthSign(authSign: Int) {
        this.authSign = authSign
    }

}
